package src.com.foreknow.demo6;

import java.util.Scanner;

public class OOPArray {
    public static void main(String[] args) {
        //创建5个对象
        Employee e1 = new Employee();
        e1.setName("aa");
        Employee e2 = new Employee();
        e2.setName("bb");
        Employee e3 = new Employee();
        e3.setName("cc");
        Employee e4 = new Employee();
        e4.setName("dd");
        Employee e5 = new Employee();
        e5.setName("ee");
        //创建一个Employee类型的数组
        Employee [] employees = new Employee[5];
        //向数组中添加Employee对象
        employees[0] = e1;
        employees[1] = e2;
        employees[2] = e3;
        employees[3] = e4;
        employees[4] = e5;
        //如何从数组中获取到下标为3的这个元素
        Employee emp = employees[3];
        System.out.println(emp.getName());
//      System.out.println(employees[3].getName());
        //遍历数组e
        for (int i = 0;i <employees.length;i++){
            Employee e = employees[i];
            System.out.println(e.getName());
        }

        //在控制台上循环录入3次员工（Employee）的信息，并输出所有员工信息
        //1.使用for循环
        //2.要求从控制台输入员工信息，每录入一次员工信息就是一个Employee对象
        //3.将这些对象使用数组来保存
        //4.遍历数组输出所有员工的信息
        Employee[] employees1 = new Employee[3];
        for (int i = 0;i <3;i++){
            Employee emp1 = new Employee();
            Scanner input = new Scanner(System.in);
            System.out.println("请输入编号：");
            int card = input.nextInt();
            emp1.setCard(card);
            System.out.println("请输入姓名：");
            String name = input.next();
            emp1.setName(name);
            System.out.println("请输入部门：");
            String date = input.next();
            emp1.setDept(date);
            System.out.println("请输入工资：");
            double salary = input.nextDouble();
            emp1.setSalary(salary);
            employees[i] = emp1;
        }
        for (int i = 0;i < employees1.length;i++){
            Employee emp1 = employees1[i];
            System.out.println(emp1.getName());
        }
    }
}




















